public class Solution50 {
    public double myPow(double x, int n) {
        double res = 1;
        boolean flag = false;
        if (n < 0) {
            x = 1 / x;
            if (n == Integer.MIN_VALUE) {
                n = Integer.MAX_VALUE;
                flag = true;
            } else {
                n = -n;
            }
        }
        double t = x;
        while (n > 0) {
            if ((n & 1) == 1) {
                res *= t;
            }
            t *= t;
            n = n >> 1;
        }
        return flag ? res * x : res;
    }

}
